#pragma once

#include "BoundingSphere.h"

namespace mgfx
{
	typedef int VertexBufferID;
	typedef int IndexBufferID;

	class Material;

	struct MeshDesc
	{
		MeshDesc()
		{
			PositionsOnly = false;
			GenerateBoundingSphere = true;
			LoadTextures = true;
		}
		std::string FileName;
		bool PositionsOnly;
		bool GenerateBoundingSphere;
		bool LoadTextures;
	};



	class Mesh
	{
	public:
		static Mesh * createFromFile(const std::string & fileName);
		static Mesh * createFromFile(const MeshDesc & desc);
		static void freeAll();

		~Mesh();

		struct Part
		{
			VertexBufferID VB;
			VertexBufferID VBPositionsOnly;
			IndexBufferID IB;
			uint NumPrimitives;
			uint NumIndices;
			mmath::BoundingSphere BSphere;
		};

		const std::vector<Part> & GetParts() const;
		bool HasBSphere;

		std::vector<Material*> Materials;

	private:
		static Mesh * fromFile(const MeshDesc & desc);

		typedef std::map<std::string, Mesh*> ResourceMap;
		static ResourceMap mResources;

		std::vector<Part> mParts;
	};
}